package br.ufpe.cin.msc.jrsj2.recommender.message;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.xml.sax.Attributes;

import br.ufpe.cin.msc.jrsj2.recommender.dto.ProfileDTO;

public class ClientProfileMessage extends ApplicationMessage {

	private String clientId;
	private String currentProgramTitle;
	private String currentChannelName;
	private List<String> availableProgramList;
	private List<String> programBlackList;
	private List<String> genreBlackList;
	private Set<ProfileDTO> preferredProgramList;

	public ClientProfileMessage() {
		clientId = new String();
		availableProgramList = new ArrayList<String>();
		preferredProgramList = new HashSet<ProfileDTO>();
		programBlackList = new ArrayList<String>();
		genreBlackList = new ArrayList<String>();
	}

	@Override
	protected void parseMessageElement(String uri, String localName,
			String qName, Attributes attributes) {
		if (qName.equals("client-profile"))
			clientId = attributes.getValue("id");
		else if (qName.equals("a-program"))
			availableProgramList.add(attributes.getValue("title"));
		else if (qName.equals("p-program")) {
			ProfileDTO profileDTO = new ProfileDTO();
			profileDTO.setProgram(attributes.getValue("title"));
			profileDTO.setChannel(attributes.getValue("channel"));
			profileDTO
					.setRating(Float.parseFloat(attributes.getValue("rating")));
			preferredProgramList.add(profileDTO);
		} else if (qName.equals("b-program"))
			programBlackList.add(attributes.getValue("title"));
		else if (qName.equals("genre"))
			genreBlackList.add(attributes.getValue("name"));
		else if (qName.equals("current-program")) {
			currentProgramTitle = attributes.getValue("title");
			currentChannelName = attributes.getValue("channel");
		}
	}

	protected void parseMessageContent(char[] ch, int start, int length) {
	}

	@Override
	protected void parseMessageEndElement(String uri, String localName,
			String qName) {
	}

	public String getClientId() {
		return this.clientId;
	}

	public String getCurrentProgramTitle() {
		return this.currentProgramTitle;
	}

	public String getCurrentChannelName() {
		return this.currentChannelName;
	}

	public List<String> getAvailableProgramList() {
		return this.availableProgramList;
	}

	public Set<ProfileDTO> getPreferredProgramList() {
		return this.preferredProgramList;
	}

	public List<String> getProgramBlackList() {
		return this.programBlackList;
	}

	public List<String> getGenreBlackList() {
		return this.genreBlackList;
	}

	public int getLength() {
		return 15;
	}

	@Override
	@SuppressWarnings("rawtypes")
	protected void buildResponseMessage(List objects) {
	}

}
